<template>
    <div>
        <a href="/Add">新增</a>
        房间号:<input type="text" placeholder="请输入房间号" v-model="ts.num">
        房号创建人:<input type="text" placeholder="请输入房间创建人" v-model="ts.name">
        <input type="button" value="查询" @click="xx">
        <input type="button" value="重置" @click="xxx">
        <table class="table">
            <thead>
                <tr>
                    <td>编号</td>
                    <td>房间号</td>
                    <td>房间名称</td>
                    <td>状态</td>
                    <td>开始时间</td>
                    <td>结束时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in date">
                    <td>{{ a.houseId }}</td>
                    <td>{{ a.houseNum }}</td>
                    <td>{{ a.houseName }}</td>
                    <td>{{ a.state?"启用":"禁用" }}</td>
                    <td>{{ moment(a.start).format("YYYY-MM-DD") }}</td>
                    <td>{{ moment(a.end).format("YYYY-MM-DD") }}</td>
                    <td>
                        <input type="button" value="修改状态" @click="upd(a.houseId)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
onMounted(()=>{
    show()
})
const upd=(val:any)=>{
    axios.get("/api/House/UpdState",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("状态修改成功")
            show();
        }
        else{
            alert("状态修改失败")
        }
    })
}
//查询
const xx=()=>{
    show()
}
//重置
const xxx=()=>{
    ts.value={
        num:'',
        name:''
    }
    show()
}
const ts=ref({
    num:'',
    name:''
})
const show=()=>{
    axios.get("/api/House/ShowHouse",{params:ts.value}).then(res=>{
        date.value=res.data
    })
}
const date=ref([{
  "houseId": 0,
  "houseNum": "",
  "houseName": "",
  "state": false,
  "start": "",
  "end": ""
}])
</script>

<style scoped>

</style>